Skip to content

added the linux font directories #469

Open
hoopes wants to merge 5 commits into
scanny:masterfrom
hoopes:linux-fonts-redux
Open

added the linux font directories #469
hoopes wants to merge 5 commits into
scanny:masterfrom
hoopes:linux-fonts-redux

Conversation

@hoopes

@hoopes hoopes commented Jan 3, 2019

Copy link
Copy Markdown
Contributor

by copying the pattern of mac/windowss font directories

@hoopes hoopes mentioned this pull request Jan 3, 2019
@hoopes

hoopes commented Jan 3, 2019

Copy link
Copy Markdown
Contributor Author

@scanny I lost the labels from the other PR. My apologies for the hassle, git and I are not simpatico sometimes. #159 . They were shortlist and text.

@scanny

scanny commented Jan 3, 2019

Copy link
Copy Markdown
Owner

@hoopes can you say a little about what Linux distros this is likely to work for? The documentation should probably mention.

@hoopes

hoopes commented Jan 5, 2019

Copy link
Copy Markdown
Contributor Author

From:
https://wiki.ubuntu.com/Fonts
https://wiki.archlinux.org/index.php/fonts
https://wiki.debian.org/Fonts
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s1-x-fonts
https://docs.fedoraproject.org/en-US/quick-docs/adding-new-fonts-fedora/

I added the /usr/local/share/fonts and ~/.local/share/fonts based on those wiki pages.

@rikardbakkehaug

Copy link
Copy Markdown

Could we please get this merged into master?

@cachemap

cachemap commented Jul 8, 2020

Copy link
Copy Markdown

I too would like to see this merged to master!

Follow up question: how does python-pptx currently load fonts on Linux systems? Does it just bundle some default fonts, or is it more nuanced than that?

@poolpoolpool

Copy link
Copy Markdown

I need this as well for the MInt distro!

@martmiskowiec

Copy link
Copy Markdown

Hey guys,
do you plan to merge it anytime soon? Would be super useful.

@philpinola1

Copy link
Copy Markdown

I would also appreciate if this was merged. Needed for Ubuntu.

@555Russich

555Russich commented Jul 23, 2023

Copy link
Copy Markdown

Did fork according @hoopes solution, thanks!
I just copied all fonts from C:\Windows\Fonts to ~/.fonts/.
Now I'm able to use tf.fit_text() on linux :)

@Verhaeg

Verhaeg commented Feb 14, 2024

Copy link
Copy Markdown

One simple way to make this work currently is to pass the desired font file instead.
Not the best way, but it works without having to depend on forks for now.

A nice improvement for this solution would be to be able to configure/pass possible paths containing font files. Look for the default locations is possible and raise exception if no folder/file is found.

@szduda

szduda commented Nov 8, 2024

Copy link
Copy Markdown
  1. IMO the line raise OSError('unsupported operating system') is misleading, because what really happens is "I did not find the font in the hardcoded paths".
  2. Some envs use a custom OS, e.g. AWS Lambda use Amazon Linux and requires different paths than e.g. Ubuntu. Instead of trying to cover all existing OSs it could first read the custom path from env and fallback to the current implementation if it's not configured.

Code improvement suggestion:

# text/fonts.py:53
    def _font_directories(cls):
        """
        Return a sequence of directory paths likely to contain fonts on the
        current platform.
        """

        CUSTOM_DIRS_VAR_NAME = 'PYTHON_PPTX_FONT_DIRECTORY'
        custom_dir = os.environ.get(CUSTOM_DIRS_VAR_NAME)

        if custom_dir is not None:
            return [custom_dir]

        if sys.platform.startswith("darwin"):
            return cls._os_x_font_directories()
        if sys.platform.startswith("win32"):
            return cls._windows_font_directories()
        raise OSError(f"No font directories are configured for your OS. Configure the path manually using {CUSTOM_DIRS_VAR_NAME} environment variable.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants